<?php

namespace app\backstage\model;
use think\Model;
use think\Db;
use think\Validate;

class GoodspecModel extends Model{
    //显示规格列表
    public function goodspeclist(){
        $data = Db::name("goods_spec")->paginate(10);
        return $data;
    }
    /*
     * 添加规格
     * guid()生成唯一标识 在common
     * $data包含(name,status)
     */
    public function goodspecadd($data){
            $log = array();
            $log['gsid'] = guid();
            $log['name'] = $data['name'];
            $log['status'] = $data['status'];
            $log['ctime'] = time();
            $result = Db::name('goods_spec')->insert($log);
            return $result;
    }
    /*
     * 修改规格
     * $data包含(name)
     */
    public function goodspecupdate($data){
        $log = array();
        $log['name'] = $data['name'];
        $result = Db::name("goods_spec")->where("id=".$data['id'])->update($log);
        return $result;
    }
    /*
     * 删除规格
     * $data包含(id)
     */
    public function goodspecdelete($data){
        $result = Db::name("goods_spec")->where("id=".$data)->delete();
        return $result;
    }
    /*
     * 更新规格状态
     * $data包含(id,status)
     */
    public function goodspecstatus($data){
        $log = array();
        $log['status'] = $data['status'];
        $result = Db::name("goods_spec")->where("id=".$data['id'])->update($log);
        return $result;
    }
    /**
     * 根据规格id获取指定的规格
    */
    public function getGone($id){
        return Db::name("goods_spec")->where("id=".$id)->find();
    }
}

